/***************************************************************************
 *   Copyright (C) 2006 by Harish Kukreja                                  *
 *   harish.kukreja@gmail.com                                              *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

//
// C++ Implementation: fields
//
// Description: Implementations of in-build fields.
//
//
// Author: Harish Kukreja <harish.kukreja@gmail.com>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include <physiksbase/fields.h>
#include <physiksbase/objects.h>

using PhysiksBase::PhysicalObject;
using PhysiksBase::Vector;

///////////////////////////////////////////////////////////////////////////////
PhysiksBase::NewtonianGravitationalField::NewtonianGravitationalField(PhysicalObject &obj) {
    center = &obj;
}

Vector PhysiksBase::NewtonianGravitationalField::operator()(const Vector &pos) const {
    Vector dist(center->position - pos);
    return Vector(GSL_CONST_MKSA_GRAVITATIONAL_CONSTANT * center->mass / (dist * dist) * dist.normalize());
}

PhysiksBase::NewtonianGravitationalField::~NewtonianGravitationalField() {}


///////////////////////////////////////////////////////////////////////////////
PhysiksBase::CoulombAccelerationField::CoulombAccelerationField(PhysicalObject &obj) {
    center = &obj;
}

Vector PhysiksBase::CoulombAccelerationField::operator()(const Vector &pos) const {
    Vector dist(center->position - pos);
    return Vector(center->charge / (GSL_CONST_MKSA_VACUUM_PERMITTIVITY * 4.0 * M_PI * (dist * dist)) * dist.normalize());
}

PhysiksBase::CoulombAccelerationField::~CoulombAccelerationField() {}
